package client;

import java.awt.*;
import javax.swing.*;

import common.User;
import common.Utilities;

public class UserRenderer extends DefaultListCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String AVAILABLE_ICO = "resource/online.png";
	private static final String OFFLINE_ICO = "resource/offline.png";

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean hasFocus) {
		JLabel label = (JLabel) super.getListCellRendererComponent(list, value,
				index, isSelected, hasFocus);
		if (value instanceof User) {
			User user = (User) value;
			if (user.getStatus() == User.STATUS_OFFLINE) {
				label.setForeground(Color.GRAY);
				label.setIcon(new ImageIcon(Utilities.createImage(OFFLINE_ICO,
						"available")));
			} else {
				label.setForeground(Color.BLUE);
				label.setIcon(new ImageIcon(Utilities.createImage(
						AVAILABLE_ICO, "available")));
			}
		}
		return label;
	}
}
